package com.power.model;



import com.power.contant.BussinessEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel("统一相应的结果")//描述实体类对象
public class Result<T> implements Serializable {

    @ApiModelProperty("状态码")
    private Integer code = 200;

    @ApiModelProperty("响应信息")
    private String message = "ok";

    @ApiModelProperty("响应数据")
    private T data;

    //有数据就返回数据 没有数据就返回null
    public static <T> Result<T> success(T data) {
        Result result = new Result();
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(Integer code,String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> fail(BussinessEnum bussinessEnum) {
        Result result = new Result();
        result.setCode(bussinessEnum.getCode());
        result.setMessage(bussinessEnum.getDesc());
        return  result;
    }


}
